package day12test;

import java.util.ArrayList;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        ArrayList<UserDate> list = new ArrayList<>();
        UserDate ud1 = new UserDate("001","爱丽丝","0101");
        UserDate ud2 = new UserDate("002","小春","0202");
        UserDate ud3 = new UserDate("003","慧慧","0303");
        list.add(ud1);
        list.add(ud2);
        list.add(ud3);
        Scanner sc = new Scanner(System.in);

        while (true) {
            System.out.println("请输入要查找的id");
            String inputId = sc.next();
            int index = indexNumber(list, inputId);
            System.out.println("索引为"+index);
            if (flag(list,inputId)){
                System.out.println(true);
                break;
            }else {
                System.out.println("id不存在");
            }
        }

    }
    public static boolean flag(ArrayList<UserDate> list, String inputId){
        for (int i = 0; i < list.size(); i++) {
            String userId = list.get(i).getId();
            if (inputId.equals(userId)){
                System.out.println(list.get(i).getId()+ "," + list.get(i).getUserName()+ "," + list.get(i).getPassWord());
                return true;
            }
        }
        return false;
    }

    public static int indexNumber(ArrayList<UserDate> list, String inputId){
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId().equals(inputId)) {
                return i;
            }
        }
        return -1;
    }
}
